package com.bolt.admin.logging.interceptor;

import com.bolt.admin.logging.util.TraceConstant;
import com.bolt.common.utils.StrUtil;
import org.slf4j.MDC;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2020/2/13.
 */
public class LogInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        // "traceId"

        String traceId = request.getHeader(TraceConstant.HTTP_HEADER_TRACE_ID);
        if (StrUtil.isNotEmpty(traceId)) {
            MDC.put(TraceConstant.LOG_TRACE_ID, traceId);
        }

        return true;
    }
}

 